package com.ecoolex.discount.sales.api.graphql;

import java.util.List;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.lang.NonNull;

import com.ecoolex.discount.sales.entity.DiscountBrandWithBLOBs;
import com.ecoolex.discount.sales.pojo.DiscountclassifyInfoDTO;
import com.ecoolex.discount.sales.pojo.QueryMarketingClassifyBrandDTO;
import com.ecoolex.discount.sales.pojo.QueryMarketingClassifyDTO;
import com.ecoolex.discount.sales.ws.DiscountProductService;
import com.ecoolex.discount.sales.ws.MarketingProductService;
import com.ecoolex.framework.common.pojo.Page;
import com.ecoolex.framework.common.pojo.Pagination;
import com.ecoolex.framework.modularize.api.service.storage.StorageInfo;
import com.ecoolex.framework.modularize.api.service.storage.StorageService;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module;
import com.ecoolex.framework.web.api.graphql2.annotation.GraphQL2Module.Type;
import com.ecoolex.framework.web.api.graphql2.annotation.QueryField;
import com.ecoolex.framework.web.api.graphql2.annotation.Source;
import com.ecoolex.framework.web.api.graphql2.annotation.TypeField;


@GraphQL2Module(type = Type.User,description = "分类营销管理")
public class MarketingClassifyGraphql {
	
	@Reference
	private MarketingProductService marketingProductService;
	
	@Reference
	private DiscountProductService discountProductService;
	
	@Autowired
	private StorageService storageService;
	
	@TypeField(type = DiscountclassifyInfoDTO.class, field = "image", description = "折扣分类图片")
	public StorageInfo coverImage(@Source DiscountclassifyInfoDTO source) {
		return storageService.get(source.getImage());
	}
	
	@TypeField(type = DiscountclassifyInfoDTO.class,field = "discountBrandList",description = "分类下品牌营销列表")
	public List<DiscountBrandWithBLOBs> discountBrandList(@Source DiscountclassifyInfoDTO source,Integer size){
		QueryMarketingClassifyBrandDTO query = new QueryMarketingClassifyBrandDTO();
		query.setClassifyId(source.getClassifyId());
		query.setPosition(source.getPosition());
		query.setRegionType(source.getRegionType());
		return discountProductService.listDiscountBrandForH5(query,size);
	}
	
	@QueryField(field = "marketingClassifyList",description = "分类营销列表")
	public Pagination<DiscountclassifyInfoDTO> query(@NonNull QueryMarketingClassifyDTO query,@NonNull Page page){
		return marketingProductService.queryMarketingClassifyForH5(query, page);
	}
}
